package com.aps.common.model;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 排程结果模型
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "排程结果模型")
public class SchedulingResult {
    
    /**
     * 排程ID
     */
    @Schema(description = "排程ID", example = "SCH001")
    private String schedulingId;
    
    /**
     * 排程时间
     */
    @Schema(description = "排程时间")
    private LocalDateTime schedulingTime;
    
    /**
     * 排程状态
     */
    @Schema(description = "排程状态", example = "成功")
    private String status;
    
    /**
     * 错误信息
     */
    @Schema(description = "错误信息")
    private String errorMessage;
    
    /**
     * 订单排程列表
     */
    @Schema(description = "订单排程列表")
    private List<OrderSchedule> orderSchedules;
    
    /**
     * 资源利用率统计
     */
    @Schema(description = "资源利用率统计")
    private Map<String, ResourceUtilization> resourceUtilizations;
    
    /**
     * 排程指标
     */
    @Schema(description = "排程指标")
    private SchedulingMetrics metrics;
    
    /**
     * 订单排程信息
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "订单排程信息")
    public static class OrderSchedule {
        @Schema(description = "订单ID", example = "ORD001")
        private String orderId;
        
        @Schema(description = "客户名称", example = "大众汽车")
        private String customerName;
        
        @Schema(description = "产品型号", example = "GEAR-001")
        private String productModel;
        
        @Schema(description = "订单数量", example = "1000")
        private Integer quantity;
        
        @Schema(description = "计划开始时间")
        private LocalDateTime plannedStartTime;
        
        @Schema(description = "计划完成时间")
        private LocalDateTime plannedEndTime;
        
        @Schema(description = "工序排程列表")
        private List<OperationSchedule> operationSchedules;
        
        @Schema(description = "优先级", example = "高")
        private String priority;
        
        @Schema(description = "客户等级", example = "A")
        private String customerLevel;
        
        @Schema(description = "交期", example = "2024-06-30")
        private String deliveryDate;
        
        @Schema(description = "订单金额", example = "50000.00")
        private Double orderAmount;
    }
    
    /**
     * 工序排程信息
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "工序排程信息")
    public static class OperationSchedule {
        @Schema(description = "工序ID", example = "OP001")
        private String operationId;
        
        @Schema(description = "工序名称", example = "车削")
        private String operationName;
        
        @Schema(description = "工序序号", example = "1")
        private Integer sequence;
        
        @Schema(description = "设备类型", example = "车床")
        private String equipmentType;
        
        @Schema(description = "计划开始时间")
        private LocalDateTime plannedStartTime;
        
        @Schema(description = "计划完成时间")
        private LocalDateTime plannedEndTime;
        
        @Schema(description = "分配的设备ID", example = "EQ001")
        private String assignedEquipmentId;
        
        @Schema(description = "分配的人员ID", example = "PER001")
        private String assignedPersonnelId;
        
        @Schema(description = "标准工时(分钟)", example = "30.0")
        private Double standardTime;
        
        @Schema(description = "换型时间(分钟)", example = "15.0")
        private Double setupTime;
        
        @Schema(description = "人员要求", example = "中级车工")
        private String personnelRequirement;
        
        @Schema(description = "质量要求", example = "表面粗糙度Ra1.6")
        private String qualityRequirement;
    }
    
    /**
     * 资源利用率
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "资源利用率")
    public static class ResourceUtilization {
        @Schema(description = "资源ID", example = "EQ001")
        private String resourceId;
        
        @Schema(description = "资源名称", example = "CNC车床")
        private String resourceName;
        
        @Schema(description = "资源类型", example = "设备")
        private String resourceType;
        
        @Schema(description = "总可用时间(分钟)", example = "480.0")
        private Double totalAvailableTime;
        
        @Schema(description = "已使用时间(分钟)", example = "360.0")
        private Double usedTime;
        
        @Schema(description = "利用率", example = "0.75")
        private Double utilizationRate;
        
        @Schema(description = "空闲时间(分钟)", example = "120.0")
        private Double idleTime;
        
        @Schema(description = "超负荷时间(分钟)", example = "0.0")
        private Double overloadTime;
    }
    
    /**
     * 排程指标
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "排程指标")
    public static class SchedulingMetrics {
        @Schema(description = "总订单数", example = "10")
        private Integer totalOrders;
        
        @Schema(description = "按时交付订单数", example = "8")
        private Integer onTimeDeliveryOrders;
        
        @Schema(description = "延迟交付订单数", example = "2")
        private Integer delayedDeliveryOrders;
        
        @Schema(description = "平均资源利用率", example = "0.85")
        private Double averageResourceUtilization;
        
        @Schema(description = "总生产时间(分钟)", example = "2400.0")
        private Double totalProductionTime;
        
        @Schema(description = "平均订单完成时间(分钟)", example = "240.0")
        private Double averageOrderCompletionTime;
        
        @Schema(description = "资源负荷均衡度", example = "0.92")
        private Double resourceBalanceScore;
        
        @Schema(description = "总完工时间(分钟)", example = "2400.0")
        private Double totalMakespan;
        
        @Schema(description = "总成本", example = "500000.0")
        private Double totalCost;
    }
}
